package com.lt.experiment06.mission01;

import java.util.ArrayList;
import java.util.List;

/**
 * @author LT
 * @version 1.0
 * @PackageName com.lt.experiment06.mission01
 * @ClassName Player
 * @Description to do
 * @date 2021/11/28 16:39
 */
public class PanelControl implements Subject{
    List<Observer> obs = new ArrayList<>();
    private String name;
    private String picture;
    private int level;
    private int combat;
    private int exp;
    private int diamond;
    private int gold;

    @Override
    public void addObserver(Observer o) {
        if(obs.contains(o)){
            return;
        }
        obs.add(o);

    }

    @Override
    public void deleteObserver(Observer o) {
        if(obs.contains(o)){
            obs.remove(o);
        }else{
            System.out.println("数组中没有该元素！删除失败");
        }
    }

    @Override
    public void notifyObservers() {
        for (Observer ob : obs) {
            ob.update(name,picture,level,combat,exp,diamond,gold);
        }
    }
    //测试用例1
    public void change1(){
        System.out.println("玩家初始化");
        this.name = "张三";
        this.picture = "张三头像";
        this.level = 999;
        this.combat = 999;
        this.exp = 999;
        this.diamond = 9999;
        this.gold = 99999;
        this.notifyObservers();
    }
    //测试用例2
    public void change2(){
        System.out.println("玩家死亡，资产全部丢失，等级减一");
        this.exp=0;
        this.level = 998;
        this.diamond = 0;
        this.gold = 0;
        this.notifyObservers();
    }
    //测试用例3
    public void change3(){
        System.out.println("玩家返回死亡地点，资产全部找回");
        this.diamond = 9999;
        this.gold = 99999;
        this.notifyObservers();
    }
}
